<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">

  <title>vprintf, vfprintf, and vsprintf</title>
  <link href="../cppreference.css" rel="stylesheet" type="text/css">
</head>

<body>
<table>
  <tr>
  <td>
  <div class="body-content">

  <div class="header-box">
    <a href="../index.html">cppreference.com</a> &gt; <a href=
    "index.html">Standard C I/O</a> &gt; <a href=
    "vprintf_vfprintf_vsprintf.html">vprintf, vfprintf, and
    vsprintf</a>
  </div>

  <div class="name-format">
    vprintf, vfprintf, and vsprintf
  </div>

  <div class="syntax-name-format">
    Syntax:
  </div>
  <pre class="syntax-box">
  #include &lt;stdarg.h&gt;
  #include &lt;stdio.h&gt;
  int vprintf( char *format, <strong>va_list</strong> arg_ptr );
  int vfprintf( FILE *stream, const char *format, <strong>va_list</strong> arg_ptr );
  int vsprintf( char *buffer, char *format, <strong>va_list</strong> arg_ptr );
</pre>

  <p>These functions are very much like <a href=
  "printf.html">printf</a>(), <a href="fprintf.html">fprintf</a>(), and
  <a href="sprintf.html">sprintf</a>(). The difference is that the
  argument list is a pointer to a list of arguments.
  <strong>va_list</strong> is defined in stdarg.h, and is also used by
  (Other Standard C Functions) <a href=
  "../stdother/va_arg.html">va_arg</a>(). For example:</p>
  <pre class="example-code">
   void error( char *fmt, ... ) {
     <strong>va_list</strong> args;
     va_start( args, fmt );
     fprintf( stderr, &quot;Error: &quot; );
     vfprintf( stderr, fmt, args );
     fprintf( stderr, &quot;\n&quot; );
     va_end( args );
     exit( 1 );
   }            
</pre>
  </div>
  </td>
  


  </tr>
  </table>
</body></html>
